package com.homework;

public class Person {
    private String name;
    private Vehicles vehicles;

    public Person(String name, Vehicles vehicles) {
        this.name = name;
        this.vehicles = vehicles;
    }
    //如何不浪费，在构建对象时，传入的交通工具对象->
    public void passRiver(){
        //判断一下，当前的vehicles属性是null,就获取一艘船
        //if(vehicles == null){
        if(!(vehicles instanceof Boat)){
            vehicles = VehiclesFactory.getBoat();
        }

        vehicles.work();

    }
    public void common(){
        //判断一下，当前的vehicles属性是null,就获取一匹马

        if(vehicles == null){
            //向上转型  多态
            vehicles = VehiclesFactory.getHorse();
        }
        //接口调用
        vehicles.work();

    }
    //过火焰山
    public void passFireHill(){
        if(!(vehicles instanceof Plane)){
            vehicles = VehiclesFactory.getPlane();
        }

        vehicles.work();
    }


}
